// indattach/dianpu/dianpu.js
const app = getApp();
Page({
    data: {
        shops: [],
        num:7,
        show:false
    },
    onLoad: function(options) {
        var that = this;
        wx.showLoading({
            title: '加载中...',
        })
        app.comrequest('https://ipass.cc/myapi/shops.php', {num:that.data.num}).then(res => {
        that.setData({
            shops: res.data,
            zlenght:res.zlenght[0].zlenght
        })
        wx.hideLoading();
        })
       
        
    },
    //搜索框
    bindLur(e) {
        var that = this;
        // console.log(e.detail.value);
        var searchvalue = e.detail.value;
        if (searchvalue.length == 0) {
            app.comrequest('https://ipass.cc/myapi/shops.php', {num:that.data.zlenght}).then(res => {
                that.setData({
                    shops: res.data
                })
            })
        } else {
            app.comrequest('https://ipass.cc/myapi/shopssreatch.php', { searchvalue: searchvalue }).then(res => {
                // console.log(res)
                if (res == "0 结果") {
                  wx.showToast({
                    title: '无该记录，请重新搜索',
                    icon: 'none',
                    duration: 1000
                 })
                } else {
                    that.setData({
                        shops: res
                    })
                }
            })
        }

    },
    onReachBottom: function() {
        var that=this;
        var zlenght=that.data.zlenght;
        var cfnum=that.data.num;
        if(cfnum>zlenght){
            that.setData({
                num:zlenght,
                show:true
            })
        }else{
            var cfnum2=cfnum+7
            that.setData({
                num:cfnum2
            })
        }
        app.comrequest('https://ipass.cc/myapi/shops.php',{num:that.data.num}).then(res=>{
        that.setData({
            shops:res.data
        })
        })
    },
    itemclick(e){
        var sitem=e.currentTarget.dataset.sitem;
        var obj=JSON.stringify(sitem)
        wx.navigateTo({
          url: '../dianpuitem/dianpuitem?sitem='+obj
        })
    }
})